<script setup>
import { ref } from 'vue'
import Home from './components/Home.vue'
import InvestmentAnalysis from './components/InvestmentAnalysis.vue'
import UserCenter from './components/UserCenter.vue'

const currentPage = ref('home')

const switchPage = (page) => {
  currentPage.value = page
}
</script>

<template>
  <div class="app-container">
    <aside class="sidebar">
      <div class="logo">
        <h2>投资分析平台</h2>
      </div>
      <nav>
        <div class="nav-item" :class="{ active: currentPage === 'home' }" @click="switchPage('home')">
          <i class="fas fa-home"></i>
          <span>首页概览</span>
        </div>
        <div class="nav-item" :class="{ active: currentPage === 'investment' }" @click="switchPage('investment')">
          <i class="fas fa-chart-line"></i>
          <span>投资分析</span>
        </div>
        <div class="nav-item" :class="{ active: currentPage === 'user' }" @click="switchPage('user')">
          <i class="fas fa-user"></i>
          <span>用户中心</span>
        </div>
      </nav>
    </aside>

    <main class="main-content">
      <header class="top-header">
        <div class="header-content">
          <div class="search-bar">
            <input type="text" placeholder="搜索...">
          </div>
          <div class="user-info">
            <span>欢迎，用户123</span>
            <img src="https://placekitten.com/40/40" alt="用户头像" class="avatar">
          </div>
        </div>
      </header>
      <div class="content-area">
        <div class="content-wrapper">
          <component :is="currentPage === 'home' ? Home : currentPage === 'investment' ? InvestmentAnalysis : UserCenter" />
        </div>
      </div>
    </main>
  </div>
</template>

<style scoped>
.app-container {
  display: flex;
  min-height: 100vh;
  max-width: 1920px;
  margin: 0 auto;
  background: #f0f2f5;
}

.sidebar {
  width: 280px;
  background: #001529;
  color: white;
  padding: 20px 0;
  position: fixed;
  height: 100vh;
  left: 0;
  z-index: 10;
}

.logo {
  padding: 20px;
  border-bottom: 1px solid #ffffff22;
}

.nav-item {
  padding: 15px 25px;
  cursor: pointer;
  transition: all 0.3s;
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav-item:hover, .nav-item.active {
  background: #1890ff;
}

.main-content {
  flex: 1;
  margin-left: 280px;
  width: calc(100% - 280px);
  min-height: 100vh;
  max-width: calc(1920px);
  margin: 0 auto 0 280px;
}

.top-header {
  background: white;
  padding: 0;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  position: fixed;
  width: 100%;
  max-width: calc(1920px);
  z-index: 5;
  left: 280px;
}

.header-content {
  padding: 15px 40px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.search-bar input {
  padding: 8px 15px;
  border: 1px solid #d9d9d9;
  border-radius: 4px;
  width: 400px;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 15px;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
}

.content-area {
  padding-top: 70px;
  padding: 90px 40px 40px 40px;
  width: 100%;
}

.content-wrapper {
  width: 100%;
  min-width: 1200px;
}

/* 媒体查询，处理小于1920px的情况 */
@media (max-width: 1920px) {
  .sidebar {
    left: 0;
  }

  .top-header {
    width: calc(100% - 280px);
    left: 280px;
  }

  .main-content {
    margin-left: 280px;
    width: calc(100% - 280px);
  }
}

/* 添加最小宽度媒体查询 */
@media (min-width: 1920px) {
  .app-container {
    width: 1920px;
    margin: 0 auto;
  }

  .sidebar {
  }

  .main-content {
    margin-left: calc(280px + (100% - 1920px) / 2);
  }

  .top-header {
    //left: calc(280px + (100% - 1920px) / 2);
  }
}
</style>
